/*
 * CarmesiConfigurationPanel.java
 *
 * Created on Apr 2, 2011, 4:01:42 AM
 */
package carmesi.webprovider;

import java.util.List;
import javax.swing.DefaultComboBoxModel;
import org.netbeans.api.project.libraries.Library;
import org.netbeans.api.project.libraries.LibraryManager;

/**
 *
 * @author Victor
 */
public class CarmesiConfigurationPanel extends javax.swing.JPanel {

    /** Creates new form CarmesiConfigurationPanel */
    public CarmesiConfigurationPanel() {
        initComponents();
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        autoGeneration.setEnabled(enabled);
        jsonSerializerClassname.setEnabled(enabled);
        carmesiLibrary.setEnabled(enabled);
        cookieAge.setEnabled(enabled);
    }
    
    public void setCarmesiLibrariesOptions(List<Library> carmesiLibraries){
        DefaultComboBoxModel model = (DefaultComboBoxModel) carmesiLibrary.getModel();
        model.removeAllElements();
        for(Library lib:carmesiLibraries){
            model.addElement(lib.getName());
        }
    }
    
    public Library getCarmesiLibrary(){
        Object selectedItem = carmesiLibrary.getSelectedItem();
        return selectedItem != null ?  LibraryManager.getDefault().getLibrary((String)selectedItem): null;
    }
    
    public int getCookieMaxAge(){
        return Integer.parseInt(cookieAge.getText());
    }
    
    public void setCookieMaxAge(int age){
        cookieAge.setText(String.valueOf(age));
    }
    
    public void setJsonSerializerClassnameOptions(String[] jsonSerializerClassnames){
        DefaultComboBoxModel model=(DefaultComboBoxModel) jsonSerializerClassname.getModel();
        model.removeAllElements();
        for (String classname : jsonSerializerClassnames) {
            model.addElement(classname);
        }
    }
    
    public String getJsonSerializerClassname(){
        return jsonSerializerClassname.getSelectedItem().toString();
    }
    
    public void setJsonSerializerClassname(String classname){
        jsonSerializerClassname.setSelectedItem(classname);
    }
    
    public boolean getAutomaticGeneration(){
        return autoGeneration.isSelected();
    }
    
    public void setAutomaticGeneration(boolean b){
        autoGeneration.setSelected(b);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        carmesiLibrary = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        autoGeneration = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        jsonSerializerClassname = new javax.swing.JComboBox();
        cookieAge = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        jLabel1.setText(org.openide.util.NbBundle.getMessage(CarmesiConfigurationPanel.class, "CarmesiConfigurationPanel.jLabel1.text")); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(CarmesiConfigurationPanel.class, "CarmesiConfigurationPanel.jPanel1.border.title"))); // NOI18N

        jLabel3.setText(org.openide.util.NbBundle.getMessage(CarmesiConfigurationPanel.class, "CarmesiConfigurationPanel.jLabel3.text")); // NOI18N

        autoGeneration.setText(org.openide.util.NbBundle.getMessage(CarmesiConfigurationPanel.class, "CarmesiConfigurationPanel.autoGeneration.text")); // NOI18N

        jLabel2.setText(org.openide.util.NbBundle.getMessage(CarmesiConfigurationPanel.class, "CarmesiConfigurationPanel.jLabel2.text")); // NOI18N

        jsonSerializerClassname.setEditable(true);
        jsonSerializerClassname.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "carmesi.json.JacksonSerializer", "carmesi.json.GsonSerializer" }));

        cookieAge.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        cookieAge.setText(org.openide.util.NbBundle.getMessage(CarmesiConfigurationPanel.class, "CarmesiConfigurationPanel.cookieAge.text")); // NOI18N

        jLabel4.setForeground(new java.awt.Color(102, 102, 102));
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText(org.openide.util.NbBundle.getMessage(CarmesiConfigurationPanel.class, "CarmesiConfigurationPanel.jLabel4.text")); // NOI18N

        jLabel5.setForeground(new java.awt.Color(102, 102, 102));
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText(org.openide.util.NbBundle.getMessage(CarmesiConfigurationPanel.class, "CarmesiConfigurationPanel.jLabel5.text")); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(autoGeneration)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(8, 8, 8)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cookieAge, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(12, 12, 12)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jsonSerializerClassname, 0, 335, Short.MAX_VALUE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cookieAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jsonSerializerClassname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(autoGeneration)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(carmesiLibrary, 0, 370, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(carmesiLibrary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox autoGeneration;
    private javax.swing.JComboBox carmesiLibrary;
    private javax.swing.JTextField cookieAge;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox jsonSerializerClassname;
    // End of variables declaration//GEN-END:variables
}
